package org.tinygroup.fulltext.impl;

import java.util.ArrayList;
import java.util.List;

import org.tinygroup.fulltext.DefaultRule;
import org.tinygroup.fulltext.FieldRule;
import org.tinygroup.fulltext.QueryRelation;
import org.tinygroup.fulltext.QueryType;
import org.tinygroup.fulltext.SearchRule;

/**
 * 默认的搜索定义实现
 * @author yancheng11334
 *
 */
public class DefaultSearchRule implements SearchRule{

	private List<FieldRule>  fieldRuleList = new ArrayList<FieldRule>();
	private DefaultRule defaultRule=null;
	
	public List<FieldRule> getFieldRuleList() {
		return fieldRuleList;
	}

	public DefaultRule getDefaultRule() {
		return defaultRule;
	}
	
	public DefaultSearchRule addField(FieldRule rule) {
		fieldRuleList.add(rule);
		return this;
	}
	
	public DefaultSearchRule addField(String name,String rule,QueryRelation relation,QueryType type) {
		return addField(new FieldRule(name,rule,relation,type));
	}
	
	public DefaultSearchRule addField(String name,String rule,QueryRelation relation) {
		return addField(name,rule,relation,QueryType.DEFAULT);
	}
	
	public DefaultSearchRule addField(String name,String rule,QueryType type) {
		return addField(name,rule,QueryRelation.AND,type);
	}
	
	public DefaultSearchRule addField(String name,String rule) {
		return addField(name,rule,QueryRelation.AND,QueryType.DEFAULT);
	}
	
	public DefaultSearchRule setDefault(DefaultRule rule) {
		defaultRule = rule;
		return this;
	}
	
	public DefaultSearchRule setDefault(String rule,QueryRelation relation,QueryType type) {
		return setDefault(new DefaultRule(rule,relation,type));
	}
	
	public DefaultSearchRule setDefault(String rule,QueryRelation relation) {
		return setDefault(rule,relation,QueryType.DEFAULT);
	}
	
	public DefaultSearchRule setDefault(String rule,QueryType type) {
		return setDefault(rule,QueryRelation.OR,type);
	}
	
	public DefaultSearchRule setDefault(String rule) {
		return setDefault(rule,QueryRelation.OR,QueryType.DEFAULT);
	}

	public String toString() {
		return "DefaultSearchRule [fieldRuleList=" + fieldRuleList
				+ ", defaultRule=" + defaultRule + "]";
	}
	
	
}
